package ooday04;



public class PolymorphicDemo {
    public static void main(String[] args) {
        Dog dog1 = new Dog("小黑",1,"黑");
        Animals dog2 = new Dog("小白",2,"白");
        Swim dog3 = new Dog("小灰",3,"灰");
        Master master = new Master();
        master.feed(dog1);
        master.feed(dog2);
        Animals[] animals = new Animals[5];
        animals[0] = new Dog("小黑",1,"黑");
        animals[1] = new Dog("小白",2,"白");
        animals[2] = new Fish("小粉",1,"粉");
        animals[3] = new Fish("小金",2,"金");
        animals[4] = new Chick("🐤",2,"黄");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Fish){
                Fish fish = (Fish) animals[i];
            }
            if (animals[i] instanceof Swim) {
                Swim swim = (Swim) animals[i];
                swim.swim();
            }

        }
        Animals o1 = new Dog("小黑",1,"黑");
        Animals o2 = new Fish("小粉",2,"粉");
        System.out.println(o1 instanceof Dog);//确保对象实际上是指定的子类对象，即o1对象实际上是指定的Dog类对象，对象 instanceof 类型，经常用于向下转型，
        Dog dog4 = (Dog)o1;
        Swim swim = (Swim)o1;
        Animals animals1 = (Animals) o1;
        System.out.println(o2 instanceof Fish);
        Fish fish = (Fish)o2;

        new Swim(){
            @Override
            public void swim() {
                System.out.println("1111");;
            }
        }.swim();

        class Mom{

        }
        class Dad{

        }
        Integer integer =new Integer(1);//将基本数据类型包装为对象
    }
}
